package com.x.crm.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.crm.dao.*;
import com.x.crm.model.*;
import com.x.crm.rpc.CrmSysParamRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@Service(interfaceName = "com.x.crm.rpc.CrmSysParamRpcService", timeout = 60000)
public class CrmSysParamService extends BaseService implements CrmSysParamRpcService {
	@Autowired
	private ChannelDao channelDao;
	@Autowired
	private CustomerLevelDao customerLevelDao;
	@Autowired
	private InsuranceDao insuranceDao;
	@Autowired
	private MortgageDao mortgageDao;
	@Autowired
	private WarrantyDao warrantyDao;
	@Autowired
	private CooperationDao cooperationDao;
	@Autowired
	private CoopertypeDao coopertypeDao;
	@Autowired
	private IntentionLevelDao intentionLevelDao;

	public List<Channel> selectChannelListAll(Channel channel) {
		try {
			return channelDao.selectChannelListAll(channel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	/**
	 * 查询不包含系统默认的参数
	 * @param channel 渠道
	 * @return
	 */
	public List<Channel> selectChannelList(Channel channel) {
		try {
			return channelDao.selectChannelList(channel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0006, e);
		}
	}

	public int selectChannelNum(Channel channel) {
		try {
			return channelDao.selectChannelNum(channel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 *查询不包含系统默认的参数数量
	 * @param channel
	 * @return
	 */
	public int selectChannelListNum(Channel channel) {
		try {
			return channelDao.selectChannelListNum(channel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}


	public String insertChannel(Channel channel) {
		try {
			return this.insert(channel).getChannelId();
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int updateChannel(Channel channel) {
		try {
			return this.update(channel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public void deleteChannel(Channel channel) {
		try {
			this.delete(channel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public List<CustomerLevel> selectCustomerLevel(CustomerLevel customerLevel) {
		try {
			return customerLevelDao.selectCustomerLevelList(customerLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}


	public List<CustomerLevel> selectCustomerLevelList(CustomerLevel customerLevel) {
		try {
			return customerLevelDao.selectLevelList(customerLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}


	public int selectCustomerLevelNum(CustomerLevel customerLevel) {
		try {
			return customerLevelDao.selectCustomerLevelNum(customerLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	public int selectCustomerLevelListNum(CustomerLevel customerLevel) {
		try {
			return customerLevelDao.selectCustomerLevelListNum(customerLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	public String insertCustomerLevel(CustomerLevel customerLevel) {
		try {
			return this.insert(customerLevel).getLevelId();
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int updateCustomerLevel(CustomerLevel customerLevel) {
		try {
			return this.update(customerLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public void deleteCustomerLevel(CustomerLevel customerLevel) {
		try {
			this.delete(customerLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public List<Insurance> selectInsuranceList(Insurance insurance) {
		try {
			return insuranceDao.selectInsuranceList(insurance);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int selectInsuranceNum(Insurance insurance) {
		try {
			return insuranceDao.selectInsuranceNum(insurance);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	public String insertInsurance(Insurance insurance) {
		try {
			return this.insert(insurance).getInsuranceId();
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int updateInsurance(Insurance insurance) {
		try {
			return this.update(insurance);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public void deleteInsurance(Insurance insurance) {
		try {
			this.delete(insurance);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public List<Mortgage> selectMortgageList(Mortgage mortgage) {
		try {
			return mortgageDao.selectMortgageList(mortgage);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int selectMortgageNum(Mortgage mortgage) {
		try {
			return mortgageDao.selectMortgageNum(mortgage);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	public String insertMortgage(Mortgage mortgage) {
		try {
			return this.insert(mortgage).getMortgageId();
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int updateMortgage(Mortgage mortgage) {
		try {
			return this.update(mortgage);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public void deleteMortgage(Mortgage mortgage) {
		try {
			this.delete(mortgage);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public List<Warranty> selectWarrantyList(Warranty warranty) {
		try {
			return warrantyDao.selectWarrantyList(warranty);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int selectWarrantyNum(Warranty warranty) {
		try {
			return warrantyDao.selectWarrantyNum(warranty);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	public String insertWarranty(Warranty warranty) {
		try {
			return this.insert(warranty).getWarrantyId();
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int updateWarranty(Warranty warranty) {
		try {
			return this.update(warranty);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public void deleteWarranty(Warranty warranty) {
		try {
			this.delete(warranty);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}



	public List<Cooperation> selectCooperationList(Cooperation cooperation) {
		try {
			return cooperationDao.selectCooperationList(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public List<Coopertype> selectCoopertypeList(Coopertype coopertype) {
		try {
			return coopertypeDao.selectCoopertypeList(coopertype);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public List<IntentionLevel> selectIntentionLevelList(IntentionLevel intentionLevel) {
		try {
			return intentionLevelDao.selectIntentionLevelList(intentionLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}


	public int selectCooperationNum(Cooperation cooperation) {
		try {
			return cooperationDao.selectCooperationNum(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int selectCoopertypeNum(Coopertype coopertype) {
		try {
			return coopertypeDao.selectCoopertypeNum(coopertype);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int selectIntentionLevelNum(IntentionLevel intentionLevel) {
		try {
			return intentionLevelDao.selectIntentionLevelNum(intentionLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public Cooperation insertCooperation(Cooperation cooperation) {
		try {
			return this.insert(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public Coopertype insertCoopertype(Coopertype coopertype) {
		try {
			coopertype.setCoopertypeNo(this.getUid(15));
			return this.insert(coopertype);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public IntentionLevel insertIntentionLevel(IntentionLevel intentionLevel) {
		try {
			return this.insert(intentionLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int updateCooperation(Cooperation cooperation) {
		try {
			return this.update(cooperation);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int  updateCoopertype(Coopertype coopertype) {
		try {
			return this.update(coopertype);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}

	public int updateIntentionLevel(IntentionLevel intentionLevel) {
		try {
			return this.update(intentionLevel);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0007, e);
		}
	}


}
